/*!
 Temelia - Tree algorithms samples.

 Copyright (C) 2008 Ceata (http://ceata.org/proiecte/temelia).

 @author Dascalu Laurentiu

 This program is free software; you can redistribute it and
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 3
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

#include "include/samples.h"
#include <temelia/tree_algorithms.h>

/*!
 * Demonstrates BFS and DFS tree travels.
 */
static void sample1(int type)
{
	int k = 0, i, j, N = 10;
	tree_t tree, root;

	PRINT("\n\n Sample 1 started \n\n");

	tree = root = tree_new(int_new(k++), type);

	for (i = 0; i < N; i++)
	{
		for (j = 0; j < i + 2; j++)
			tree_add_child(tree, tree_new(int_new(k++), type));
		tree = tree_get_child(tree, 0);
	}

	PRINT("\n\nPrinting the tree in BFS order ...\n");
	tree_bfs_iterate(root, int_handler, NULL);

	PRINT("\n\nPrinting the tree in DFS order ...\n");
	tree_dfs_iterate(root, int_handler, NULL);

	tree_dfs_iterate(root, int_delete, NULL);

	tree_delete(root);

	PRINT("\n\n Sample 1 ended \n\n");
}

void run_tree_algorithms_samples()
{
	//INIT(stdout);

	// Vector backbone
	sample1(0);

	// Linked list backbone
	sample1(1);

	//DESTROY();
}
